package com.ruoyi.web.controller.hotel;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.hotel.domain.HotelHouse;
import com.ruoyi.hotel.service.IHotelHouseService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 房间Controller
 *
 * @author ruoyi
 * @date 2024-11-15
 */
@RestController
@RequestMapping("/hotel/house")
@Api(tags = "房间")
public class HotelHouseController extends BaseController
{
    @Autowired
    private IHotelHouseService hotelHouseService;

    /**
     * 查询房间列表
     */
    @PreAuthorize("@ss.hasPermi('hotel:house:list')")
    @GetMapping("/list")
    @ApiOperation(value = "查询房间列表")
    public TableDataInfo list(HotelHouse hotelHouse)
    {
        startPage();
        List<HotelHouse> list = hotelHouseService.selectHotelHouseList(hotelHouse);
        return getDataTable(list);
    }


    /**
     * 导出房间列表
     */
    @PreAuthorize("@ss.hasPermi('hotel:house:export')")
    @Log(title = "房间", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HotelHouse hotelHouse)
    {
        List<HotelHouse> list = hotelHouseService.selectHotelHouseList(hotelHouse);
        ExcelUtil<HotelHouse> util = new ExcelUtil<HotelHouse>(HotelHouse.class);
        util.exportExcel(response, list, "房间数据");
    }

    /**
     * 获取房间详细信息
     */
    @PreAuthorize("@ss.hasPermi('hotel:house:query')")
    @GetMapping(value = "/{houseId}")
    public AjaxResult getInfo(@PathVariable("houseId") Long houseId)
    {
        return success(hotelHouseService.selectHotelHouseByHouseId(houseId));
    }

    /**
     * 新增房间
     */
    @PreAuthorize("@ss.hasPermi('hotel:house:add')")
    @Log(title = "房间", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HotelHouse hotelHouse)
    {
        if (!hotelHouseService.checkHouseNumUnique(hotelHouse))
        {
            return error("新增'" + hotelHouse.getHouseNum() + "'失败，房号已存在");
        }
        hotelHouse.setCreateId(getUserId());
        return toAjax(hotelHouseService.insertHotelHouse(hotelHouse));
    }

    /**
     * 修改房间
     */
    @PreAuthorize("@ss.hasPermi('hotel:house:edit')")
    @Log(title = "房间", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HotelHouse hotelHouse)
    {
        if (!hotelHouseService.checkHouseNumUnique(hotelHouse))
        {
            return error("修改'" + hotelHouse.getHouseNum() + "'失败，房号已存在");
        }
        hotelHouse.setUpdateId(getUserId());
        return toAjax(hotelHouseService.updateHotelHouse(hotelHouse));
    }

    /**
     * 删除房间
     */
    @PreAuthorize("@ss.hasPermi('hotel:house:remove')")
    @Log(title = "房间", businessType = BusinessType.DELETE)
	@DeleteMapping("/{houseIds}")
    public AjaxResult remove(@PathVariable Long[] houseIds)
    {
        return toAjax(hotelHouseService.deleteHotelHouseByHouseIds(houseIds));
    }
}
